package com.zm.order.controller;


import com.zm.order.model.Order;
import com.zm.order.service.OrderService;
import com.zm.order.service.OrderTCCService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class SeateController {
    @Autowired
    private OrderService orderService;
    @RequestMapping("/createOrder/{userId}/{productId}")
    @Transactional
    public Long Order(@PathVariable("userId") Long userId,@PathVariable("productId") Long productId) {
        Long orderId=0L;
        if (userId!=null&&productId!=null){
            orderId = orderService.createOrder(userId, productId);
        }
        return orderId;
    }
    ///////////////////////////////////////////////////////
    @Autowired
    private OrderTCCService orderTCCService;
    @RequestMapping("/createOrderTCC/{userId}/{productId}")
    @Transactional
    public Long OrderTCC(@PathVariable("userId") Long userId,@PathVariable("productId") Long productId) {
        Long orderId=0L;
        try {
            if (userId!=null&&productId!=null){
                orderId = orderTCCService.createOrder(userId, productId);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return orderId;
    }
}
